package pisa.puzzle;

import java.awt.Color;
import java.awt.Graphics;

public class Clue {
	// Information about location in grid
	private int xPos, yPos;

	// Fill color for square behind clue
	// ONLY USE FOR CELL-CENTERED CLUES
	private Color fillColor = null;

	// Shapes, like cross-outs, arrows, less-than/greater-than signs,
	// circles, etc.
	// Can be set visible/invisible
	// Can be set filled/unfilled
	private int[] shapeX = null;
	private int[] shapeY = null;
	private Color shapeLine = null;
	private Color shapeFill = null;
	private boolean shapeFilled = false;
	private boolean shapeVisible = false;

	// Big text in the center of the clue
	private String text = null;
	private Color textColor = null;

	// Smaller text that appears in the top-left corner of the clue
	private String textAnn = null;
	private Color textAnnColor = null;
	private boolean textAnnVisible = false;

	public Clue(int x, int y) {
		this.xPos = x; this.yPos = y;
	}

	public void setShape(int[] shapeX, int[] shapeY, Color line) {
		this.shapeX = shapeX; this.shapeY = shapeY;
		this.shapeLine = line;
	}
	public void setShape(int[] shapeX, int[] shapeY, Color line, Color fill) {
		this.shapeX = shapeX; this.shapeY = shapeY;
		this.shapeLine = line; this.shapeFill = fill;
		this.shapeVisible = true;
	}
	public void setShapeLine(Color line) {
		this.shapeLine = line;
	}
	public void setShapeFill(Color fill) {
		this.shapeFill = fill;
	}
	public void setShapeFilled(boolean filled) {
		this.shapeFilled = filled;
	}
	public void setShapeVisible(boolean visible) {
		this.shapeVisible = visible;
	}

	public void setText(String text) {
		this.text = text;
	}
	public void setTextColor(Color textColor) {
		this.textColor = textColor;
	}

	public void setAnnotationText(String text) {
		this.textAnn = text;
	}
	public void setAnnotationTextColor(Color textColor) {
		this.textAnnColor = textColor;
	}
	public void setAnnotationTextVisible(boolean visible) {
		this.textAnnVisible = visible;
	}

	public void draw(Graphics g, double zoom, int margin, int cellWidth) {
		int xOffset = margin+cellWidth*xPos;
		int yOffset = margin+cellWidth*yPos;
		if(fillColor != null) {
			g.setColor(fillColor);
			g.fillRect(xOffset, yOffset, cellWidth, cellWidth);
		}
		if(shapeVisible && shapeLine != null) {
			if(shapeFilled) {
				g.setColor(shapeFill);
				g.fillPolygon(adjust(shapeX, zoom, xOffset),
						adjust(shapeY, zoom, yOffset), shapeX.length);
			}
			g.setColor(shapeLine);
			g.drawPolygon(adjust(shapeX, zoom, xOffset),
					adjust(shapeY, zoom, yOffset), shapeX.length);
		}
		// TODO Display text as centered in box at scaled font size
		// TODO Display annotation text as top-left in box at 1/3? scaled font size
	}
	private int[] adjust(int[] nums, double zoom, int offset) {
		int[] ret = new int[nums.length];
		for(int i = 0; i < nums.length; i++) {
			ret[i] = (int)(nums[i]*zoom + offset);
		}
		return ret;
	}
}